/**
 * 
 */
package edu.pku.sei.modeler.uml.commands.component;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.uml.Interfaces.Interface;
import edu.pku.sei.modeler.model.uml.InternalStructures.Connector;
import edu.pku.sei.modeler.model.uml.Ports.Port;
import edu.pku.sei.modeler.uml.commands.ConnectionModelCreateCommand;

/**
 * @author YanYan
 *
 */
public class CreateDelegationCommand extends ConnectionModelCreateCommand {

	public CreateDelegationCommand(MetaModelElement connectionModel, MetaModelElement sourceModel) {
		super(connectionModel, sourceModel);
	}

	public boolean canExecute() {
		return true;
	}
	
	public void execute() {
		Connector delegation = (Connector) connectionModel;
		if(sourceModel != null){
			if(sourceModel instanceof Interface)
				((Interface)sourceModel).getOutgoing().add(delegation);
			else if(sourceModel instanceof Port)
				((Port)sourceModel).getOutgoing().add(delegation);
		}
		if(targetModel != null){
			if(targetModel instanceof Interface)
				((Interface)targetModel).getIncoming().add(delegation);
			else if(targetModel instanceof Port)
				((Port)targetModel).getIncoming().add(delegation);
		}
		if(delegation != null){
			delegation.setContainer(sourceModel);
			delegation.setModel(sourceModel.getModel());
		}
	}
	
	//TODO: undo & redo
	public void undo() {
	}
	public void redo() {	
	}
}
